#ifndef __ENCODER_H__
#define __ENCODER_H__
 
#include "stm32f1xx_hal.h"

#define STORAGE_SPACE 5

typedef enum{
	CONFIRM = 1,
	BACK = 2,
	VALUE = 3,
	NONE = 4,
}encoder_state_t;

typedef enum{
	KEY_CONFIRM = 1,
	KEY_BACK = 2,
}encoder_key_state_t;

typedef struct{
	//0 is the latest
	int value[STORAGE_SPACE];
	int speed[STORAGE_SPACE];
	int key;
	encoder_key_state_t key_state;
	encoder_state_t state;
}encoder_t;

extern encoder_t encoder_s;

void encoder_read_value(TIM_HandleTypeDef *htim,encoder_t *encoder);
void encoder_state_recognize(encoder_t *encoder);

#endif
